<?php

namespace App\Http\Controllers\Admin\Member;

use App\Http\Controllers\Controller;

use App\Models\MemberCardBatch;

use App\Traits\Controllers\AdminTraits;
use App\Traits\Controllers\DestroyTraits;
use App\Traits\Controllers\IndexTraits;
use App\Traits\Controllers\ShowTraits;
use App\Traits\Controllers\StoreTraits;
use App\Traits\Controllers\UpdateStatusTraits;
use App\Traits\Controllers\UpdateTraits;
use App\Transformers\Member\MemberCardBatchTransFormer;
use Illuminate\Http\Request;

class MemberCardBatchController extends Controller
{
    use IndexTraits,StoreTraits,ShowTraits,DestroyTraits;
    use UpdateStatusTraits;

    public $model = MemberCardBatch ::class;

    public $transformer = MemberCardBatchTransFormer::class;

    public function updatedTitle(MemberCardBatch $memberCardBatch,Request $request)
    {
        $request->validate([
            'title'=>'required'
        ],[
            'title.required'=>'名称不能为空'
        ]);
       $memberCardBatch = $this->getQuery()
           ->find($memberCardBatch->id);
      $memberCardBatch->title = $request->input('title');
      $memberCardBatch->save();
      return $this->response->noContent();

    }




    /**
     * 参数验证规则
     *
     * @param Request $request
     * @return array
     */
    public function rules(Request $request): array
    {
        switch ($request->method()) {
            case 'GET':
                return [];
                break;
            case 'PUT':
                return [];
                break;
            case 'PATCH':
                return [
                    'title' => 'required|max:255',
                ];
                break;
            case 'POST':
                return [
                    'title' => 'required|max:255',
                    'total_num' => 'required',
                    'use_start_time' => 'required',
                    'use_end_time' => 'required',
                    'use_day' => 'required',
                    'sort' => 'required',
                    'qrcode' => 'required',
                    'status' => 'required',
                    'remark' => 'required|max:32',
                ];
                break;

        }
        return [];
    }

    /**
     * 验证信息
     *
     * @return array
     */
    public function ruleMessages(): array
    {
        return [
            'title.required' => '批次名称 不能为空',
            'title.max' => '批次名称 不能超过225字符',
            'total_num.required' => '数量必填',
            'use_start_time.required' => '开始使用时间不能为 空',
            'use_end_time.required' => '使用结束时间不能为空',
            'use_day.required' => '使用天数不能为空',
            'sort.required' => '排序不能为空',
            'status.required' => '状态不能为空',
            'remark.required' => '备注不能为空',
            'remark.max' => '备注不能超过32字符',
            'qrcode.required' => '二维码路径不能为空',
        ];
    }

}
